namespace SimpleWebServices.Models
{
    using System;
    using System.Xml.Serialization;
    using SimpleWebServices.Data;

    [XmlRoot("session")]
    public sealed class FormSession : Record
    {
        public FormSession()
        {
            this.Data = new DataCollection();
        }

        [XmlElement("data")]
        public DataCollection Data
        {
            get;
            set;
        }

        [XmlIgnore]
        public override string Entity
        {
            get
            {
                Entity value = new Entity();
                value.Append(this.Data);

                return value;
            }
        }

        public static AbsoluteUri FormatUrn(Token token)
        {
            if (Guid.Empty.Equals(token))
            {
                throw new ArgumentOutOfRangeException("token");
            }

            return "urn://session/" + token;
        }

        public void Store()
        {
            this.Store<FormSession>();
        }
    }
}